package com.funtl.spring.cloud.alibaba.consumer.controller;

import com.funtl.spring.cloud.alibaba.consumer.service.EchoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName TestController
 * @Description
 * @Author Mr-CHEN
 * @Date 2019/9/10 0010 15:41
 * @Version V1.0
 **/

@RestController
public class TestController {

    private final RestTemplate restTemplate;

    @Autowired
    public TestController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }


    @Autowired
    private EchoService echoService;

    @GetMapping(value = "/echo/{str}")
    public String echoResr(@PathVariable String str) {
        // 使用服务名请求服务提供者
        return restTemplate.getForObject("http://service-provider/echo/" + str, String.class);
    }


    @GetMapping(value = "/feign/echo/{str}")
    public String echoFeign(@PathVariable String str) {
        return echoService.echo(str);
    }


    @GetMapping(value = "/lb")
    public String lb() {
        return echoService.lb();
    }
}